package com.horizon.im.imClient.clientBuilder;

import com.horizon.im.common.bean.UserDTO;
import com.horizon.im.common.bean.msg.ProtoMsg;
import com.horizon.im.imClient.client.ClientSession;

public class LoginMsgBuilder extends BaseBuilder{
    private final UserDTO user;

    public LoginMsgBuilder(
            UserDTO user,
            ClientSession session)
    {
        super(ProtoMsg.HeadType.LOGIN_REQUEST, session);
        this.user = user;
    }

    public ProtoMsg.Message build() {
        ProtoMsg.Message msg = buildCommand(-1);
        ProtoMsg.LoginRequest.Builder lb=
                ProtoMsg.LoginRequest.newBuilder()
                .setDeviceId(user.getDevId())
                .setPlatform(user.getPlatform().ordinal())
                .setToken(user.getToken())
                .setUid(user.getUserId());
        return msg.toBuilder().setLoginRequest(lb).build();

    }

    public static ProtoMsg.Message buildLoginMsg(
            UserDTO user,
            ClientSession session)
    {
        LoginMsgBuilder builder = new LoginMsgBuilder(user, session);
        return builder.build();

    }
}
